import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
  },
  {
    path: '/',
    name: '/',
    component: () => import('../layout'),
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home/index.vue')
      },
      {
        path: 'firm',
        name: 'firm',
        component: () => import('@/views/firm/index.vue')
      },
      {
        path: 'CallRoll',
        name: 'CallRoll',
        component: () => import('@/views/CallRoll/index.vue')
      },
      {
        path: 'Management',
        name: 'Management',
        component: () => import('@/views/Management/index.vue')
      },
      {
        path: 'boxList',
        name: 'boxList',
        component: () => import('@/views/box/boxList/index.vue')
      },
      {
        path: 'boxTag',
        name: 'boxTag',
        component: () => import('@/views/box/boxTag/index.vue')
      },
      {
        path: 'boxClassify',
        name: 'boxClassify',
        component: () => import('@/views/box/boxClassify/index.vue')
      },

      {
        path: 'TeacherDetail',
        name: 'TeacherDetail',
        component: () => import('@/views/shopping/TeacherDetail/index.vue')
      },
      {
        path: 'shoppingList',
        name: 'shoppingList',
        component: () => import('@/views/shopping/shoppingList/index.vue')
      },
      {
        path: 'shoppingOrderList',
        name: 'shoppingOrderList',
        component: () => import('@/views/shopping/shoppingOrderList/index.vue')
      },
      {
        path: 'shoppingSlideshow',
        name: 'shoppingSlideshow',
        component: () => import('@/views/shopping/shoppingSlideshow/index.vue')
      },
      {
        path: 'goodsClassify',
        name: 'goodsClassify',
        component: () => import('@/views/goods/goodsClassify/index.vue')
      },
      {
        path: 'ClassDetail',
        name: 'ClassDetail',
        component: () => import('@/views/goods/ClassDetail/index.vue')
      },
      {
        path: 'Course',
        name: 'Course',
        component: () => import('@/views/goods/Course/index.vue')
      },
      {
        path: 'Consumption',
        name: 'Consumption',
        component: () => import('@/views/goods/Consumption/index.vue')
      },
      {
        path: 'IncomeExpenditure',
        name: 'IncomeExpenditure',
        component: () => import('@/views/goods/IncomeExpenditure/index.vue')
      },
      {
        path: 'ParentsMeeting',
        name: 'ParentsMeeting',
        component: () => import('@/views/goods/ParentsMeeting/index.vue')
      },
      {
        path: 'goodsList',
        name: 'goodsList',
        component: () => import('@/views/goods/goodsList/index.vue')
      },
      {
        path: 'goodsOrderList',
        name: 'goodsOrderList',
        component: () => import('@/views/goods/goodsOrderList/index.vue')
      },
      {
        path: 'TSITeachingPlan',
        name: 'TSITeachingPlan',
        component: () => import('@/views/configured/TSITeachingPlan/index.vue')
      },
      {
        path: 'REPTeachingPlan',
        name: 'REPTeachingPlan',
        component: () => import('@/views/configured/REPTeachingPlan/index.vue')
      },
      {
        path: 'WondersTeachingPlan',
        name: 'WondersTeachingPlan',
        component: () => import('@/views/configured/WondersTeachingPlan/index.vue')
      },
      {
        path: 'ThinkTeachingPlan',
        name: 'ThinkTeachingPlan',
        component: () => import('@/views/configured/ThinkTeachingPlan/index.vue')
      },


      {
        path: 'userList',
        name: 'userList',
        component: () => import('@/views/user/userList/index.vue')
      },
      {
        path: 'userPay',
        name: 'userPay',
        component: () => import('@/views/user/userPay/index.vue')
      },
      {
        path: 'userRecord',
        name: 'userRecord',
        component: () => import('@/views/user/userRecord/index.vue')
      },
      {
        path: 'userOrder',
        name: 'userOrder',
        component: () => import('@/views/user/userOrder/index.vue')
      },
      
      
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to,from,next)=>{
  const token = localStorage.getItem('token')
  if(!token && to.path !='/login'){
    next('/login')
  } else{
    next()
  }
})


export default router
